package top.tangyh.lamp.care.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.lamp.care.entity.BCareRecordsConfig;
import org.springframework.stereotype.Repository;
import top.tangyh.lamp.common.constant.CommonConstant;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 护理记录表单配置表
 * </p>
 *
 * @author zqb
 * @date 2024-07-18 10:49:14
 * @create [2024-07-18 10:49:14] [zqb] [代码生成器生成]
 */
@Repository
public interface BCareRecordsConfigMapper extends SuperMapper<BCareRecordsConfig> {

    default List<BCareRecordsConfig> selectMainByCode(String modelCode){
        LambdaQueryWrapper<BCareRecordsConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BCareRecordsConfig::getDictValue,modelCode).eq(BCareRecordsConfig::getPid,0).eq(BCareRecordsConfig::getIsDeleted, CommonConstant.NO_NUMBER);
        return selectList(queryWrapper);
    }

    default List<BCareRecordsConfig> selectDetailByPidAndCode(Integer id, String itemCode){
        LambdaQueryWrapper<BCareRecordsConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BCareRecordsConfig::getPid,id).eq(BCareRecordsConfig::getItemCode,itemCode).eq(BCareRecordsConfig::getIsDeleted,CommonConstant.NO_NUMBER);
        return selectList(queryWrapper);
    }

    default List<BCareRecordsConfig> selectMaxWeightDetailByPid(Integer id){
        LambdaQueryWrapper<BCareRecordsConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BCareRecordsConfig::getPid,id)
                .eq(BCareRecordsConfig::getIsDeleted,CommonConstant.NO_NUMBER)
                .orderByDesc(BCareRecordsConfig::getWeights).last(" limit 1");
        return selectList(queryWrapper);
    }
}


